// 简历投递成功
<template>
  <div class="resumeDeliveredSuccess">
    <div class="main">
      <el-card class="messageBox-card" v-show="isSuccess">
        <div class="messageBox">
          <div class="successIcon">
            <img src="../../../assets/img/resume/successResume-icon.png" alt />
          </div>
          <div class="successWord">
            <p>恭喜您，简历投递成功!</p>
            <p>
              <a href="#" @click="goHome">返回首页</a>
            </p>
          </div>
        </div>
      </el-card>
      <el-card class="isCheckAll-card">
        <el-row class="isCheckAll-row">
          <el-col :span="4" class="tips-col">
            <span class="tips">根据求职意向为您推荐</span>
          </el-col>
          <el-col :span="20">
            <el-checkbox :indeterminate="isIndeterminate" v-model="checkAll" @change="handleCheckAllChange">全选
            </el-checkbox>
            <el-button type="primary" size="small" class="apply" @click="apply">一键申请</el-button>
          </el-col>
        </el-row>
      </el-card>
      <div class="dataList">
        <el-card class="listContainer" v-for="(item, index) in recommendPostData" :key="index">
          <el-checkbox-group v-model="checkedResumes" @change="handleCheckedCitiesChange">
            <div class="list">
              <div class="logo">
                <img :src="((item.companyInfo && item.companyInfo.logo) || require('../../../assets/img/qiye.png'))"
                  alt />
              </div>
              <div class="basicInfo">
                <p class="postWages">
                  <span class="post text-nobr" @click="goDetailPage(item)">{{item.name || '暂无'}}</span>
                  <span class="wages">{{item.wageText || '暂无'}}</span>
                  <!-- <span class="wages">{{(item.minWageText + '-' + item.maxWageText) || '暂无'}}</span> -->
                </p>
                <p class="educatWorkYears">
                  <span class="education">{{item.educationText || '学历不限'}}&nbsp;&nbsp;|</span>
                  <span class="workYears">&nbsp;&nbsp;{{item.workExpText || '经验不限'}}</span>
                </p>
                <p class="postWages">
                  <span class="compaName">{{(item.companyInfo && item.companyInfo.name) || '暂无'}}</span>
                  <el-checkbox :label="item" :key="index"><span></span></el-checkbox>
                </p>
              </div>
            </div>
          </el-checkbox-group>
        </el-card>
      </div>
      <div class="seeMore">
        <span @click="clickMore">查看更多</span>
      </div>
      <!-- <recommended-post-resume :recommendPostData='recommendPostData' v-if="isShow"></recommended-post-resume> -->
    </div>

    <!-- 选择 简历弹框 -->
    <el-dialog width="30%" :visible.sync="dialogVisible" class="elDialog" :before-close="closeResume"
      :append-to-body="false">
      <p slot="title" class="selectResumeHeader">
        <span>请选择投递的简历</span>
      </p>
      <div class="elDialog-content">
        <el-row>
          <el-select v-model="selectedResume" placeholder="请选择" popper-class="popper-class">
            <el-option v-for="item in resumelist" :key="item.id" :label="item.title" :value="item.id"></el-option>
          </el-select>
          <div class="checkouts">
            <el-checkbox v-model="resumeChecked">将该份简历设置为快速投递(推荐)</el-checkbox>
          </div>
        </el-row>
      </div>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="immediateDelivery">立即投递</el-button>
      </div>
    </el-dialog>
  </div>
</template>
<script>
import { list, gitInterface, deliverSave, isExpress } from '../../../api/index.js';
// import recommendedPostResume from './recommendedPostResume.vue';
export default {
  name: 'resumeDeliveredSuccess',
  data () {
    return {
      // 是都全部申请
      isAll: false,
      url: '',
      checkAll: false,
      isIndeterminate: false,
      checkedResumes: [],
      isSuccess: true,
      category: '', // 职位类别
      currentPage: 1,
      // 推荐职位容器
      recommendPostData: [],
      isShow: false,
      // 企业id
      companyId: '',
      // 简历列表
      resumelist: [],
      resumeId: '', // 简历id
      // 控制弹框开关
      dialogVisible: false,
      selectedResume: '', // 选中的简历
      // 将该份简历设置为快速投递
      resumeChecked: false,
      // 控制下面查看更多按钮的开关
      isSeeMore: false,
      sort: [{ column: 'refresh_time', type: 'desc' }],
    };
  },
  created () {
    console.log(this.$route.query, '获取地址栏参数');
    // 获取默认路径
    this.url = process.env.VUE_APP_URL;
    this.companyId = this.$route.query.companyId;
    this.category = this.$route.query.category; // 获取职位类别
  },
  components: {
    // recommendedPostResume
  },
  mounted () {
    this.initialiData();
  },
  methods: {
    // 初始化数据
    initialiData () {
      this.getRecommendPostList();
    },
    // 获取推荐职位列表
    getRecommendPostList () {
      let personHopeJob = [];
      personHopeJob.push({ "column": 'person_hope_job', "type": '', "value": this.category });
      personHopeJob.push({ "column": "include", "type": "", "value": "D,CI" })
      personHopeJob.push({ "column": "re_resume_deliver_user_id", "type": "", "value": "userId" })
      personHopeJob.push({ "column": "status", "type": "eq", "value": 1 }); //过滤待审核的职位
      var formData = new FormData();
      formData.append('page', this.currentPage);
      formData.append('size', 12);
      formData.append('condition', JSON.stringify(personHopeJob))
      formData.append('sort', JSON.stringify(this.sort));
      // column: 公司id 的字段 eq 等于或者大于 value:公司id 值[{column: "person_hope_job",type: "eq", value: "category值"}]
      // [{column: "name",type: "asc"},{column: "company_id",type: "desc 倒序"}]
      list(formData).then(res => {
        console.log(res, '推荐职位列表');
        if (res.success) {
          this.recommendPostData = res.data.records || [];
          if (res.data.total > 12) {
            this.isSeeMore = true;
          }
        } else {
          this.$message.error(`${res.msg}`);
        }
      });
    },
    // 获取简历列表
    getResumeList () { },
    // 申请职位
    getApplyPosition () {
      let idArr = [];
      let that = this;
      that.checkedResumes.map(item => {
        console.log(item, 'item');
        idArr.push({
          jobId: item.id,
          companyId: item.companyId
        });
      });
      // var formData = new FormData();
      // formData.append('dataJson', JSON.stringify(idArr));
      // formData.append('userId', localStorage.getItem('ps_userId'));
      // formData.append('resumeId', this.resumeId);
      // feat： 后端更改了传递的参数格式
      let formData = {
        "resumeId": this.resumeId,
        "dataJson": idArr
      }
      deliverSave(formData).then(res => {
        console.log(res, '一键申请响应');
        if (res.success) {
          // let datas = res.data
          that.$message({
            message: '申请成功',
            type: 'success'
          });
          that.checkedResumes = [];
          that.checkAll = false;
          that.isIndeterminate = false;
        } else {
          that.$message.error(res.msg);
          // that.checkedResumes = [];
          // that.checkAll = false;
        }
      });
    },
    //    点击全选
    handleCheckAllChange (val) {
      console.log(val);
      this.checkedResumes = val ? this.recommendPostData : [];
      this.isIndeterminate = false;
    },
    // 返回首页
    goHome () {
      this.$router.push('/JobHunting');
    },
    handleCheckedCitiesChange (value) {
      console.log(value);
      let checkedCount = value.length;
      this.checkAll = checkedCount === this.recommendPostData.length;
      this.isIndeterminate = checkedCount > 0 && checkedCount < this.recommendPostData.length;
    },
    // 点击一键申请全部
    apply () {
      let that = this;
      if (that.checkedResumes.length <= 0) {
        this.$message.error('请选择推荐的职位');
        return false;
      }
      this.isLogin()
      // 查看简历
      gitInterface().then(res => {
        console.log(res, '查看简历列表');
        if (res.success) {
          let data = res.data;
          this.resumelist = res.data;
          let isFlag = false; // 声明一个开关变量
          data.forEach(item => {
            //  express= true 为默认简历
            if (item.express) {
              isFlag = true;
              this.resumeId = item.id; // 获取简历id
            }
          });
          if (isFlag) {
            // 直接申请
            this.getApplyPosition();
          } else {
            //   弹框出现
            this.dialogVisible = true;
          }
        } else {
          this.$message.error(`${res.msg}`);
        }
      });
    },
    // 立即申请
    immediateDelivery () {
      // if (!localStorage.getItem('ps_Authorization')) {
      //   this.$message.error('请先进行登录');
      //   let that = this;
      //   setTimeout(() => {
      //     window.location.href = that.url + '/person/#/login';
      //   }, 3000);
      //   return false;
      // }
      if (!this.selectedResume) {
        this.$message.error('请选择简历');
        return false;
      }
      let idArr = [];
      this.checkedResumes.forEach(checkItem => {
        idArr.push({
          jobId: checkItem.id,
          companyId: checkItem.companyId
        });
      });
      //   [{ jobId: "7", companyId: "99be9bc7bf9f9d2d9cb7b83d99e8958a" }, { jobId: "4", companyId: "99be9bc7bf9f9d2d9cb7b83d99e8958a" }]
      // var formData = new FormData();
      // formData.append('dataJson', JSON.stringify(idArr));
      // formData.append('userId', localStorage.getItem('ps_userId'));
      // formData.append('resumeId', this.selectedResume);
      let formData = {
        "resumeId": this.selectedResume,
        "dataJson": idArr
      }
      deliverSave(formData).then(res => {
        if (res.success) {
          this.$message({
            message: '投递成功',
            type: 'success'
          });
          this.dialogVisible = false;
          // this.isSuccess = true;
          this.checkedResumes = [];
          this.isIndeterminate = false;
          this.selectedResume = '';
          // 如果说有设置快速投递 则调用设置快速投递接口
          if (this.resumeChecked) {
            //  调用是否默认简历头覅
            this.updateExpress();
          } else {
            this.selectedResume = '';
          }
        } else {
          this.$message.error(res.msg);
          this.checkedResumes = [];
          this.checkAll = false;
          this.isIndeterminate = false;
          this.dialogVisible = false;
        }
      });
    },
    // 是否默认设置为此建立为快速投递投递简历
    updateExpress () {
      let obj = {
        express: this.resumeChecked,
        id: this.selectedResume
      };
      isExpress(obj).then(res => {
        console.log('设置默认简历', res);
        if (res.success) {
          this.dialogVisible = false;
          this.selectedResume = '';
          this.resumeChecked = false;
          console.log('设置未默认简历成功');
        } else {
          this.$message.error(`${res.msg}`)
        }
      });
    },
    // 关闭弹框
    closeResume () {
      this.dialogVisible = false;
      if (!this.resumeChecked) {
        this.selectedResume = '';
      }
    },
    // 点击查看更多
    clickMore () {
      this.$router.push('/JobHunting')
    },
    // 点击职位名称进职位详情页
    goDetailPage (obj) {
      const { href } = this.$router.resolve({
        path: "/JobHunting/jobdetail",
        query: {
          id: obj.id
        }
      });
      window.open(href, '_blank');
    },
    // 判断用户是否登陆
    isLogin () {
      if (!localStorage.getItem('ps_Authorization')) {
        this.$message.error('您还没有登录，请先进行登录')
        return false
      }
    },
  }
};
</script>
<style lang="css" scoped>
.resumeDeliveredSuccess {
    margin-top: 30px;
}
.resumeDeliveredSuccess .main {
    width: 1200px;
    margin: 0 auto;
    padding-bottom: 90px;
}
.messageBox-card {
    height: 120px;
    box-sizing: border-box;
}
.messageBox {
    display: flex;
    padding-top: 8px;
}
.messageBox .successIcon {
    flex: 1;
    text-align: right;
    padding-right: 12px;
    padding-right: 6px;
}
.messageBox .successIcon img {
    width: 54px;
    height: 64px;
}
.messageBox .successWord {
    flex: 1;
    padding-left: 6px;
    padding-top: 6px;
}
.messageBox .successWord p {
    font-size: 20px;
    height: 28px;
    line-height: 16px;
    color: #222222;
}
.messageBox .successWord p a {
    width: 64px;
    height: 22px;
    font-size: 16px;
    font-family: PingFang SC;
    font-weight: 500;
    line-height: 16px;
    color: #159b3e;
}

.isCheckAll-card {
    margin: 16px auto;
    height: 50px;
    box-sizing: border-box;
}
.isCheckAll-card /deep/ .el-card__body {
    padding: 13px 20px;
}
.isCheckAll-row {
    box-sizing: border-box;
}
.isCheckAll-row .tips {
    width: 140px;
    height: 24px;
    font-size: 14px;
    font-family: PingFang SC;
    font-weight: 500;
    line-height: 24px;
    color: rgba(85, 85, 85, 1);
    opacity: 1;
}
.apply {
    width: 94px;
    height: 24px;
    background: #1893fc;
    line-height: 6px;
    margin-left: 32px;
}
/* .recommendedPostResume  */
.dataList {
    display: -webkit-box;
    display: -moz-box;
    display: -ms-flexbox;
    display: -webkit-flex;
    display: flex;
    flex-wrap: wrap;
    box-sizing: border-box;
}
.dataList .el-card {
    /* background: chartreuse; */
    width: 32%;
    margin-right: 2%;
    margin-bottom: 18px;
    box-sizing: border-box;
}
.dataList .el-card:nth-child(3n + 1) {
    margin-left: 0;
}
.dataList .el-card:nth-child(3n) {
    margin-right: 0;
}

.listContainer {
    height: 130px;
}
.list {
    display: flex;
}
.logo {
    width: 68px;
    height: 68px;
    margin-left: 10px;
    margin-top: 10px;
    /* background: #C0C4CC; */
    background: rgba(242, 242, 242, 1);
    opacity: 1;
}
.logo img {
    width: 100%;
    height: 100%;
}
.basicInfo {
    margin-left: 20px;
    display: flex;
    flex-direction: column;
    flex: 1;
}
.basicInfo p {
    height: 22px;
    width: 100%;
}
.basicInfo .postWages {
    display: flex;
    justify-content: space-between;
}
.basicInfo .educatWorkYears {
    padding-top: 10px;
    padding-bottom: 10px;
}
.basicInfo p .post {
    max-width: 160px;
    height: 22px;
    font-size: 16px;
    font-family: PingFang SC;
    font-weight: 600;
    line-height: 22px;
    color: #222222;
    cursor: pointer;
}
.postWages .post:hover {
    color: #2d8cf0;
}
.basicInfo p .wages {
    /* width: 52px; */
    height: 22px;
    font-size: 16px;
    font-family: PingFang SC;
    font-weight: 600;
    line-height: 22px;
    color: #fd4e40;
}
.basicInfo p .education,
.basicInfo p .workYears,
.basicInfo p .compaName {
    height: 20px;
    font-size: 14px;
    font-family: PingFang SC;
    font-weight: 400;
    line-height: 16px;
    color: #555555;
}
.seeMore {
    text-align: center;
    margin-top: 25px;
}
.seeMore span {
    display: inline-block;
    width: 340px;
    height: 40px;
    line-height: 40px;
    border: 1px solid #1893fc;
    cursor: pointer;
    font-size: 16px;
    font-family: PingFang SC;
    color: #1893fc;
    font-weight: 400;
}
/* 弹框样式 */
.checkouts /deep/ .el-checkbox {
    margin-top: 10px;
}
.elDialog-content {
    height: 100px;
    padding-top: 10px;
    box-sizing: border-box;
}
</style>